home *** CD-ROM | disk | FTP | other *** search
/ The Best of MacTutor - S…e Code for Volumes 1 to 5 / The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin / Source Code / #50 (Nov 89) / SC#50.sit / XCMD Code / Listing 1 of XCMD Corner next >
Text File  |  1989-09-11  |  2KB  |  86 lines

  1. /********************************/
  2. /* File: Catalog.c                */
  3. /*                                */
  4. /* Given the reference number of*/
  5. /* a working directory or volume*/
  6. /* return a list of all files & */
  7. /* folders in that directory    */
  8. /*                                */
  9. /* if a name is given, use it,    */
  10. /* otherwise, use the id passed    */
  11. /* ----------------------------    */
  12. /********************************/
  13.  
  14. #include    <MacTypes.h>
  15. #include    <OSUtil.h>
  16. #include    <MemoryMgr.h>
  17. #include    <FileMgr.h>
  18. #include    <ResourceMgr.h>
  19. #include    <pascal.h>
  20. #include    <string.h>
  21. #include    <hfs.h>
  22. #include     "HyperXCmd.h"
  23. #include    "HyperUtils.h"
  24.  
  25. #define        nil        0L
  26.  
  27. extern    GetCatalog();
  28.  
  29. pascal void main( paramPtr )
  30.     XCmdBlockPtr    paramPtr;
  31. {
  32.     Handle            catalog;
  33.     Str31            str;
  34.     short            dirID;
  35.  
  36.  
  37.     /*** intialize the output container            ***/
  38.     catalog = NewHandle( 0L );
  39.     
  40.     /*** convert the wdid to a usable form         ***/
  41.     if( paramPtr->params[1] ){
  42.         HLock( paramPtr->params[1] );
  43.         ZeroToPas( paramPtr, *(paramPtr->params[1]), &str );
  44.         HUnlock( paramPtr->params[1] );
  45.         dirID = (short)StrToNum( paramPtr, &str );
  46.  
  47.         /*** given the id of a directory,             ***/
  48.         /*** return a catalog for that directory     ***/
  49.         GetCatalog( dirID, catalog );
  50.     }
  51.     else if( paramPtr->params[0] ){    
  52.         char        path[256];
  53.         CInfoPBRec    catPB;
  54.         WDPBRec        wdPB;
  55.         
  56.         HLock( paramPtr->params[0] );
  57.         ZeroToPas( paramPtr, *(paramPtr->params[0]), &path );
  58.         HUnlock( paramPtr->params[0] );
  59.         
  60.         /*** get a directory id to this path    ***/        
  61.         catPB.dirInfo.ioNamePtr     = (StringPtr)path;
  62.         catPB.dirInfo.ioFDirIndex     = 0;
  63.         catPB.dirInfo.ioVRefNum     = 0;
  64.         if( PBGetCatInfo( &catPB, 0 ) == noErr )
  65.              if( catPB.dirInfo.ioFlAttrib & 0x010 ){    /*** it's a directory    ***/
  66.                 wdPB.ioNamePtr     = (StringPtr)path; 
  67.                  wdPB.ioWDProcID = 0;
  68.                  
  69.                 if( PBOpenWD( &wdPB, 0 ) == noErr ){
  70.                     wdPB.ioWDVRefNum= catPB.dirInfo.ioVRefNum;
  71.                     wdPB.ioWDDirID     = catPB.dirInfo.ioDrDirID;
  72.                     GetCatalog( wdPB.ioVRefNum, catalog );
  73.                     PBCloseWD( &wdPB, 0 );
  74.                 }
  75.          }
  76.     }
  77.     
  78.  
  79.     /*** append a null to the end of the        ***/
  80.     /*** the directory for Hypercard            ***/
  81.     AppendCharToHandle( catalog, '\0' );
  82.     
  83.     paramPtr->returnValue = catalog;
  84. }
  85.  
  86.